$(function(){
    $(".hide_box").fadeToggle();
    $(".shang_box").fadeToggle();
    var res = {
        orCode :$("#orderCode").val(),
        paynum:$("#payNum").val()
    };
    $.ajax({
        type: 'post',
        url:'/api/paliPay',
        async: true,
        data:JSON.stringify(res),
        contentType: "text/html;charset=UTF-8",
        success:function(data) {
            var imgBase = JSON.parse(data);
            if(imgBase.code==20000){
                $(".shang_payimg img").attr("src",'data:image/jpeg;base64,'+imgBase.data);
                InterValPay=window.setInterval(checkPay, 1000);
            }
        }
    });
    $(".pay_item").click(function(){
        $(this).addClass('checked').siblings('.pay_item').removeClass('checked');
        var dataid=$(this).attr('data-id');
        if (dataid=="alipay"){
            var res = {
                orCode :$("#orderCode").val(),
                paynum:$("#payNum").val()
            };
            $.ajax({
                type: 'post',
                url:'/api/paliPay',
                async: true,
                data:JSON.stringify(res),
                contentType: "text/html;charset=UTF-8",
                success:function(data) {
                    var imgBase = JSON.parse(data);
                    if(imgBase.code==20000){
                        $(".shang_payimg img").attr("src",'data:image/jpeg;base64,'+imgBase.data);
                        InterValPay=window.setInterval(checkPay, 1000);
                    }
                }
            });
        }
        else if (dataid=="weipay"){
            var res = {
                orCode :$("#orderCode").val(),
                paynum:$("#payNum").val()
            };
            $.ajax({
                type: 'post',
                url: '/api/pwpay',
                async: true,
                data:JSON.stringify(res),
                contentType: "text/html;charset=UTF-8",
                success:function(data) {
                    var imgBase = JSON.parse(data);
                    if(imgBase.code==20000){
                        // $("#wxpayqrcode").attr('src', 'data:image/jpeg;base64,'+imgBase.data);
                        $(".shang_payimg img").attr("src",'data:image/jpeg;base64,'+imgBase.data);
                        InterValPay=window.setInterval(checkPay, 1000);
                    }

                }
            });
        }
        // $(".shang_payimg img").attr("src","/picture/"+dataid+"img.jpg");
        $("#shang_pay_txt").text(dataid=="alipay"?"支付宝":"微信");
    });
});
function dashangToggle(){
    $(".hide_box").fadeToggle();
    $(".shang_box").fadeToggle();
}
function checkPay() {
    var res = {
        ordercode:$("#orderCode").val(),
        payresult:'1'
    };
    $.ajax({
        type: 'post',
        url: '/api/payorder/getOrderByCode',
        data:JSON.stringify(res),
        dataType: "json",
        async: false,
        contentType: "application/json;charset=UTF-8",
        success: function (data) {
            if (data.code==20000) {
                window.clearInterval(InterValPay);
                //alert("支付成功！");
                window.location.href = '/pcpaycg/'+$("#orderCode").val();
            }
        }
    })
}